<%--
  Created by IntelliJ IDEA.
  User: qinxiaoyao
  Date: 2015/11/16
  Time: 18:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="org.apache.shiro.web.filter.authc.FormAuthenticationFilter" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <!-- Bootstrap Core CSS -->
    <link href="${ctxStatic}/css/bootstrap.css" rel="stylesheet">
    <!-- Custom CSS -->
    <link href="${ctxStatic}/css/smartech.css" rel="stylesheet">
    <!-- Custom Fonts -->
    <link href="${ctxStatic}/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <title></title>
    <style>
        body {
            background-color: #FFFFFF
        }

    </style>
    <script>
        var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
        function fileChange(target, id) {
            var fileSize = 0;
            var filetypes = [".jpg", ".png", ".bmp", ".jpeg", ".gif", ".JPG", ".PNG", ".JPEG", ".BMP", ".GIF"];
            var filepath = target.value;
            var filemaxsize = 1024 * 2;
            if (filepath) {
                var isnext = false;
                var fileend = filepath.substring(filepath.indexOf("."));
                if (filetypes && filetypes.length > 0) {
                    for (var i = 0; i < filetypes.length; i++) {
                        if (filetypes[i] == fileend) {
                            isnext = true;
                            break;
                        }
                    }
                }
                if (!isnext) {
                    alert("不接受此文件类型！");
                    target.value = "";
                    return false;
                }
            } else {
                return false;
            }
            //kfsjflsdklfjsdljfks
            if (isIE && target.files) {
                var filePath = target.value;
                var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
                if (!fileSystem.FileExists(filepath)) {
                    alert("附件不存在，请重新输入！");
                    return false;
                }
                var file = fileSystem.GetFile(filePath);
                fileSize = target.files.size;
            } else {
                fileSize = target.files[0].size;
            }
            var size = fileSize / 1024;
            if (size > filemaxsize) {
                alert("附件不能大于" + filemaxsize / 1024 + "M!");
                target.value = "";
                return false;
            }
            document.getElementById("fileForm").submit();
        }

    </script>
</head>
<body>
<form:form id="fileForm" action="${ctx}/sys/user/uploadLogoImage" method="post" enctype="multipart/form-data">
    <c:if test="${empty path}">
        <img src="${ctxroot}/static/img/profile-8.jpg" height="50" style="border: 0px" class="img-rounded margin-right" width="140">
    </c:if>
    <c:if test="${not empty path}">
        <img src="${ctxroot}${path}" height="50" style="border: 0px" class="img-rounded margin-right" width="140">
    </c:if>
       <span class="inputfile">
          <span class="btn btn-primary"><i class="fa fa-upload"></i> 选择</span>
          <input name="imgFile" type="file"
                 style=" position: absolute;top: 8px;left: 170px;opacity: 0;width: 70px;height: 34px;"
                 onchange="fileChange(this)"/>
       </span>
</form:form>
<span class="help-block">注：请上传图片为PNG/JPG/png/jpg,比例为140:50的图片，大小小于2M</span>
</body>
</html>
